{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyPf7pjRspAVh8k8vMRhABT1",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/sugarforever/LangChain-Advanced/blob/main/Retrievers/04_MultiVector_Retriever/04_MultiVector_Retriever.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# 04 MultiVector Retriever\n",
        "\n",
        "To improve the retrieval effectiveness, in practice we can store multiple vectors per document. It's been proved in multiple use cases.\n",
        "\n",
        "LangChain provides a retriever component `MultiVectorRetriever` which support such mechanism. It can be implemented in the following methods:\n",
        "\n",
        "- Smaller Chunks\n",
        "  \n",
        "  Split a document into smaller chunks, and embed them.\n",
        "\n",
        "- Summary\n",
        "\n",
        "  Create a summary for each document, embed that along with (or instead of) the document.\n",
        "\n",
        "- Hypothetical questions\n",
        "\n",
        "  Create hypothetical questions that each document would be appropriate to answer, embed those along with (or instead of) the document."
      ],
      "metadata": {
        "id": "cUbNOf6aAD2w"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Smaller Chunks"
      ],
      "metadata": {
        "id": "ZCMb8QtOBawT"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xPWZLTgY5E_4",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "1633c7e4-3235-4a7e-dd4f-c35365379f96"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m18.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.0/77.0 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m448.1/448.1 kB\u001b[0m \u001b[31m31.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m62.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m276.6/276.6 kB\u001b[0m \u001b[31m23.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m40.0/40.0 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m83.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.3/66.3 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m59.5/59.5 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.4/5.4 MB\u001b[0m \u001b[31m58.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.2/6.2 MB\u001b[0m \u001b[31m65.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.8/3.8 MB\u001b[0m \u001b[31m92.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
            "  Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
            "  Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m593.7/593.7 kB\u001b[0m \u001b[31m47.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.4/49.4 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.0/67.0 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m295.0/295.0 kB\u001b[0m \u001b[31m25.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m428.8/428.8 kB\u001b[0m \u001b[31m31.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.2/4.2 MB\u001b[0m \u001b[31m82.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m57.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m129.9/129.9 kB\u001b[0m \u001b[31m9.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m9.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
          ]
        }
      ],
      "source": [
        "!pip install -q -U langchain openai chromadb tiktoken pypdf"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!wget -O nvidia_10q_2023.pdf https://d18rn0p25nwr6d.cloudfront.net/CIK-0001045810/19771e6b-cc29-4027-899e-51a0c386111e.pdf"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5k5zSl2WU1dJ",
        "outputId": "76f80f52-7293-4278-c3f5-b5765b6262c9"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "--2023-10-15 20:15:41--  https://d18rn0p25nwr6d.cloudfront.net/CIK-0001045810/19771e6b-cc29-4027-899e-51a0c386111e.pdf\n",
            "Resolving d18rn0p25nwr6d.cloudfront.net (d18rn0p25nwr6d.cloudfront.net)... 18.64.171.68, 18.64.171.136, 18.64.171.43, ...\n",
            "Connecting to d18rn0p25nwr6d.cloudfront.net (d18rn0p25nwr6d.cloudfront.net)|18.64.171.68|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 458891 (448K) [application/pdf]\n",
            "Saving to: ‘nvidia_10q_2023.pdf’\n",
            "\n",
            "nvidia_10q_2023.pdf 100%[===================>] 448.14K  --.-KB/s    in 0.09s   \n",
            "\n",
            "2023-10-15 20:15:41 (4.97 MB/s) - ‘nvidia_10q_2023.pdf’ saved [458891/458891]\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "os.environ['OPENAI_API_KEY'] = \"your valid openai api key\""
      ],
      "metadata": {
        "id": "eVQjKJn-5ZZZ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.retrievers.multi_vector import MultiVectorRetriever\n",
        "from langchain.vectorstores import Chroma\n",
        "from langchain.embeddings import OpenAIEmbeddings\n",
        "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
        "from langchain.storage import InMemoryStore\n",
        "from langchain.document_loaders import PyPDFLoader"
      ],
      "metadata": {
        "id": "7qjgj56XSn5E"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "loaders = [ PyPDFLoader('./nvidia_10q_2023.pdf') ]\n",
        "docs = []\n",
        "for l in loaders:\n",
        "    docs.extend(l.load())\n",
        "text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000)\n",
        "docs = text_splitter.split_documents(docs)"
      ],
      "metadata": {
        "id": "c3AaAGMvUTtw"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "len(docs)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "a2dgeXqVRSQn",
        "outputId": "b851b033-cbe6-4622-a944-bab5d85bcf2e"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "51"
            ]
          },
          "metadata": {},
          "execution_count": 47
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(docs[6])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "j456ZG8EV02g",
        "outputId": "381b681a-b7a2-4704-abfc-1c45033f4352"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "page_content=\"NVIDIA CORPORATION AND SUBSIDIARIES\\nCONDENSED CONSOLIDATED STATEMENTS OF SHAREHOLDERS’ EQUITY\\nFOR THE SIX MONTHS ENDED JULY 30, 2023 AND JULY 31, 2022\\n(Unaudited)\\nCommon Stock\\nOutstandingAdditional\\nPaid-in\\nCapitalAccumulated Other\\nComprehensive LossRetained\\nEarningsTotal\\nShareholders'\\nEquity (In millions, except per share data) Shares Amount\\nBalances, January 29, 2023 2,466 $ 2 $ 11,971 $ (43) $ 10,171 $ 22,101 \\nNet income — — — — 8,232 8,232 \\nOther comprehensive loss — — — (8) — (8)\\nIssuance of common stock from stock plans 14 — 247 — — 247 \\nTax withholding related to vesting of restricted stock units (3) — (1,179) — — (1,179)\\nShares repurchased (8) — (1) — (3,283) (3,284)\\nCash dividends declared and paid ($0.08 per common share) — — — — (199) (199)\\nStock-based compensation — — 1,591 — — 1,591 \\nBalances, July 30, 2023 2,469 $ 2 $ 12,629 $ (51) $ 14,921 $ 27,501 \\nBalances, January 30, 2022 2,506 $ 3 $ 10,385 $ (11) $ 16,235 $ 26,612 \\nNet income — — — — 2,274 2,274 \\nOther comprehensive loss — — — (79) — (79)\\nIssuance of common stock from stock plans 15 — 205 — — 205 \\nTax withholding related to vesting of restricted stock units (4) — (837) — — (837)\\nShares repurchased (28) (1) (2) — (5,338) (5,341)\\nCash dividends declared and paid ($0.08 per common share) — — — — (200) (200)\\nStock-based compensation — — 1,217 — — 1,217 \\nBalances, July 31, 2022 2,489 $ 2 $ 10,968 $ (90) $ 12,971 $ 23,851 \\nSee accompanying Notes to Condensed Consolidated Financial Statements.\\n7\" metadata={'source': './nvidia_10q_2023.pdf', 'page': 6}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# The vectorstore to use to index the child chunks\n",
        "vectorstore = Chroma(\n",
        "    collection_name=\"full_documents\",\n",
        "    embedding_function=OpenAIEmbeddings()\n",
        ")\n",
        "# The storage layer for the parent documents\n",
        "store = InMemoryStore()\n",
        "id_key = \"doc_id\"\n",
        "# The retriever (empty to start)\n",
        "retriever = MultiVectorRetriever(\n",
        "    vectorstore=vectorstore,\n",
        "    docstore=store,\n",
        "    id_key=id_key,\n",
        ")\n",
        "import uuid\n",
        "doc_ids = [str(uuid.uuid4()) for _ in docs]"
      ],
      "metadata": {
        "id": "kmhj21qEUVv-"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# The splitter to use to create smaller chunks\n",
        "child_text_splitter = RecursiveCharacterTextSplitter(chunk_size=400)"
      ],
      "metadata": {
        "id": "0y4CJ-ryUY7S"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "sub_docs = []\n",
        "for i, doc in enumerate(docs):\n",
        "    _id = doc_ids[i]\n",
        "    _sub_docs = child_text_splitter.split_documents([doc])\n",
        "    for _doc in _sub_docs:\n",
        "        _doc.metadata[id_key] = _id\n",
        "    sub_docs.extend(_sub_docs)"
      ],
      "metadata": {
        "id": "7nUwAvpQUabD"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print(sub_docs[1])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "nW4h19MbWw9v",
        "outputId": "5ed4ffe8-01e7-4f33-e34b-784f749edc38"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "page_content='For the quarterly period ended July 30, 2023\\nOR\\n☐ TRANSITION REPORT PURSUANT T O SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934\\nCommission file number: 0-23985\\nNVIDIA CORPORATION\\n(Exact name of registrant as specified in its charter)\\nDelaware 94-3177549\\n(State or other jurisdiction of (I.R.S. Employer\\nincorporation or organization) Identification No.)' metadata={'source': './nvidia_10q_2023.pdf', 'page': 0, 'doc_id': 'bad39a26-308b-4d75-918e-59ee4976c9e4'}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "retriever.vectorstore.add_documents(sub_docs)\n",
        "retriever.docstore.mset(list(zip(doc_ids, docs)))"
      ],
      "metadata": {
        "id": "PrhdE-c3UeL1"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Vectorstore alone retrieves the small chunks\n",
        "similar_docs = retriever.vectorstore.similarity_search(\"What is the gross margin?\")"
      ],
      "metadata": {
        "id": "Hag4cePtUgSY"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "similar_docs"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "EpCflzceXZ7H",
        "outputId": "5a3b11aa-9de8-47cc-8937-8da6fa6f3beb"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[Document(page_content='Gross margin increased from a year ago and sequentially, primarily reflecting growth in Data Center sales. The year-on-year increase also\\nreflects the impact on the year-ago gross margin from $1.34 billion in inventory provisions and related charges.\\nOperating expenses were up 10% from a year ago and up 6% sequentially, primarily driven by compensation and benefits, including stock-based', metadata={'doc_id': '3cd9d92f-c3d9-49cc-9528-d94ac2790659', 'page': 26, 'source': './nvidia_10q_2023.pdf'}),\n",
              " Document(page_content='Gross margin increased from a year ago and sequentially, primarily reflecting growth in Data Center sales. The year-on-year increase also\\nreflects the impact on the year-ago gross margin from $1.34 billion in inventory provisions and related charges.\\nOperating expenses were up 10% from a year ago and up 6% sequentially, primarily driven by compensation and benefits, including stock-based', metadata={'doc_id': 'b37124b4-df02-48a4-808d-66f8764063a9', 'page': 26, 'source': './nvidia_10q_2023.pdf'}),\n",
              " Document(page_content='distributors, and channel partners. We expect this concentration trend will continue.\\nGross Margin\\nOur overall gross margin increased to 70.1% and 68.2% for the second quarter and first half of fiscal year 2024, respectively, from 43.5% and\\n55.7% for the second quarter and first half of fiscal year 2023, respectively. The increase in the second quarter and first half of fiscal year 2024', metadata={'doc_id': 'd1017743-8663-45dc-a0dc-7ed3891da15b', 'page': 28, 'source': './nvidia_10q_2023.pdf'}),\n",
              " Document(page_content='distributors, and channel partners. We expect this concentration trend will continue.\\nGross Margin\\nOur overall gross margin increased to 70.1% and 68.2% for the second quarter and first half of fiscal year 2024, respectively, from 43.5% and\\n55.7% for the second quarter and first half of fiscal year 2023, respectively. The increase in the second quarter and first half of fiscal year 2024', metadata={'doc_id': 'ab132857-2998-4ce1-9c7f-697620116063', 'page': 28, 'source': './nvidia_10q_2023.pdf'})]"
            ]
          },
          "metadata": {},
          "execution_count": 54
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "relevant_docs = retriever.get_relevant_documents(\"What is the gross margin?\")"
      ],
      "metadata": {
        "id": "0lEmkyy6Xkdg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "len(relevant_docs)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "OgSN1_1AXpQF",
        "outputId": "ac27e095-916d-46c3-9f38-c791ce398389"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2"
            ]
          },
          "metadata": {},
          "execution_count": 56
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "relevant_docs[0]"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2cQfjMwYUim4",
        "outputId": "987955fe-0508-41ae-f1cb-ef3c714e39d5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Document(page_content='Second Quarter of Fiscal Year 2024 Summary\\nThree Months Ended\\n July 30, 2023 April 30, 2023 July 31, 2022Quarter-over-Quarter\\nChangeYear-over-Year\\nChange\\n($ in millions, except per share data)\\nRevenue $ 13,507 $ 7,192 $ 6,704 88 % 101 %\\nGross margin 70.1 % 64.6 % 43.5 % 5.5 pts 26.6 pts\\nOperating expenses $ 2,662 $ 2,508 $ 2,416 6 % 10 %\\nOperating income $ 6,800 $ 2,140 $ 499 218 % 1,263 %\\nNet income $ 6,188 $ 2,043 $ 656 203 % 843 %\\nNet income per diluted share $ 2.48 $ 0.82 $ 0.26 202 % 854 %\\nWe specialize in markets where our computing platforms can provide tremendous acceleration for applications. These platforms incorporate\\nprocessors, interconnects, software, algorithms, systems, and services to deliver unique value. Our platforms address four large markets where\\nour expertise is critical: Data Center, Gaming, Professional Visualization, and Automotive.\\nRevenue for the second quarter of fiscal year 2024 was $13.51 billion, up 101% from a year ago and up 88% sequentially.\\nData Center revenue was up 171% from a year ago and up 141% sequentially, led by CSPs and large consumer internet companies. Strong\\ndemand for the NVIDIA HGX platform based on our Hopper and Ampere GPU architectures was primarily driven by the development of large\\nlanguage models and generative AI. Data Center Compute grew 195% from a year ago and 157% sequentially, largely reflecting the strong ramp\\nof our Hopper-based HGX platform. Networking was up 94% from a year ago and up 85% sequentially, primarily on strong growth in InfiniBand\\ninfrastructure to support our HGX platform. In the second quarter of fiscal year 2024, CSPs represented slightly more than half of our estimated\\nData Center end demand, with large consumer internet companies being the next largest end demand, followed by enterprise and high\\nperformance computing.\\nGaming revenue was up 22% from a year ago and up 11% sequentially, primarily reflecting demand for our GeForce RTX 40 Series GPUs\\nbased on the NVIDIA Ada Lovelace architecture following normalization of channel inventory levels.\\nProfessional Visualization revenue was down 24% from a year ago and up 28% sequentially. The year-on-year decrease primarily reflects lower\\nsell-in to partners following normalization of channel inventory levels. The sequential increase was primarily due to stronger enterprise\\nworkstation demand and the ramp of NVIDIA RTX products based on the Ada Lovelace Architecture.\\nAutomotive revenue was up 15% from a year ago and down 15% sequentially. The year-on-year increase was primarily driven by sales of self-\\ndriving platforms. The sequential decrease primarily reflects lower overall auto demand, particularly in China.\\nGross margin increased from a year ago and sequentially, primarily reflecting growth in Data Center sales. The year-on-year increase also\\nreflects the impact on the year-ago gross margin from $1.34 billion in inventory provisions and related charges.\\nOperating expenses were up 10% from a year ago and up 6% sequentially, primarily driven by compensation and benefits, including stock-based\\ncompensation, reflecting growth in employees and compensation increases.\\nMarket Platform Highlights\\nData Center revenue for the second quarter of fiscal year 2024 was $10.32 billion, up 171% from a year ago. We announced that the NVIDIA\\nGH200 Grace Hopper Superchip is available in the third quarter of fiscal year 2024; announced the NVIDIA L40S GPU - a universal data center\\nprocessor for compute-intensive applications, including AI training and inference, is available now; unveiled the NVIDIA MGX server reference\\ndesign; announced NVIDIA Spectrum-X, an accelerated networking platform for AI; and partnered with a\\n27', metadata={'source': './nvidia_10q_2023.pdf', 'page': 26})"
            ]
          },
          "metadata": {},
          "execution_count": 57
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.memory import ConversationBufferMemory\n",
        "memory = ConversationBufferMemory(memory_key=\"chat_history\", return_messages=True)"
      ],
      "metadata": {
        "id": "8I8GadUe-Gt6"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.llms import OpenAI\n",
        "from langchain.chains import ConversationalRetrievalChain\n",
        "qa = ConversationalRetrievalChain.from_llm(OpenAI(temperature=0), retriever, memory=memory)"
      ],
      "metadata": {
        "id": "xHDh_8-AXiLm"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "result = qa({\"question\": \"What is the gross margin?\"})"
      ],
      "metadata": {
        "id": "saVFclVQ-RW_"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "result"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ga1XtNY4-VOD",
        "outputId": "d533d61b-deaa-4bcb-f094-d76051817b4c"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'What is the gross margin?',\n",
              " 'chat_history': [HumanMessage(content='What is the gross margin?'),\n",
              "  AIMessage(content=' The gross margin for the second quarter and first half of fiscal year 2024 was 70.1% and 68.2%, respectively.')],\n",
              " 'answer': ' The gross margin for the second quarter and first half of fiscal year 2024 was 70.1% and 68.2%, respectively.'}"
            ]
          },
          "metadata": {},
          "execution_count": 61
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "result = qa({\"question\": \"What is the main contribution to it?\"})\n",
        "result"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "W8eN25Nu_1Lu",
        "outputId": "2e00ae2f-ff79-40ac-cf5f-ae6c3ea2f5e9"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'What is the main contribution to it?',\n",
              " 'chat_history': [HumanMessage(content='What is the gross margin?'),\n",
              "  AIMessage(content=' The gross margin for the second quarter and first half of fiscal year 2024 was 70.1% and 68.2%, respectively.'),\n",
              "  HumanMessage(content='What is the main contribution to it?'),\n",
              "  AIMessage(content=' Higher revenue from Compute GPUs of 208% and 112%, respectively, and lower inventory provisions.')],\n",
              " 'answer': ' Higher revenue from Compute GPUs of 208% and 112%, respectively, and lower inventory provisions.'}"
            ]
          },
          "metadata": {},
          "execution_count": 62
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Summary"
      ],
      "metadata": {
        "id": "RTAs02IgBnFa"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.chat_models import ChatOpenAI\n",
        "from langchain.prompts import ChatPromptTemplate\n",
        "from langchain.schema.output_parser import StrOutputParser\n",
        "import uuid\n",
        "from langchain.schema.document import Document"
      ],
      "metadata": {
        "id": "oNIQd43kBohz"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "chain = (\n",
        "    {\"doc\": lambda x: x.page_content}\n",
        "    | ChatPromptTemplate.from_template(\"Summarize the following document:\\n\\n{doc}\")\n",
        "    | ChatOpenAI(max_retries=0)\n",
        "    | StrOutputParser()\n",
        ")"
      ],
      "metadata": {
        "id": "mZORyWgiBrGj"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "summaries = chain.batch(docs, {\"max_concurrency\": 5})"
      ],
      "metadata": {
        "id": "1UavJZHkBtzu"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# The vectorstore to use to index the child chunks\n",
        "vectorstore = Chroma(\n",
        "    collection_name=\"summaries\",\n",
        "    embedding_function=OpenAIEmbeddings()\n",
        ")\n",
        "# The storage layer for the parent documents\n",
        "store = InMemoryStore()\n",
        "id_key = \"doc_id\"\n",
        "# The retriever (empty to start)\n",
        "retriever = MultiVectorRetriever(\n",
        "    vectorstore=vectorstore,\n",
        "    docstore=store,\n",
        "    id_key=id_key,\n",
        ")\n",
        "doc_ids = [str(uuid.uuid4()) for _ in docs]"
      ],
      "metadata": {
        "id": "rBP-6rNdBzen"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "summary_docs = [Document(page_content=s,metadata={id_key: doc_ids[i]}) for i, s in enumerate(summaries)]"
      ],
      "metadata": {
        "id": "pQt2bSRaB34v"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "retriever.vectorstore.add_documents(summary_docs)\n",
        "retriever.docstore.mset(list(zip(doc_ids, docs)))"
      ],
      "metadata": {
        "id": "-Rtaxd17B9LZ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "sub_docs = vectorstore.similarity_search(\"What is the gross margin?\")\n",
        "sub_docs[0]"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "eTEeztrcB_TS",
        "outputId": "356a667c-9df6-4403-90e8-4ddb11c7f953"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Document(page_content=\"In the second quarter of fiscal year 2024, the company's revenue was $13.51 billion, an increase of 101% compared to the previous year and 88% sequentially. The Data Center sector saw significant growth, with revenue up 171% year-on-year and 141% sequentially. Gaming revenue increased by 22% year-on-year and 11% sequentially. Professional Visualization revenue decreased by 24% year-on-year, but increased by 28% sequentially. Automotive revenue increased by 15% year-on-year, but decreased by 15% sequentially. Gross margin also increased, primarily due to growth in Data Center sales. Operating expenses increased by 10% year-on-year and 6% sequentially.\", metadata={'doc_id': 'c43be092-0450-4d24-a169-68c5867e372a'})"
            ]
          },
          "metadata": {},
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "retrieved_docs = retriever.get_relevant_documents(\"What is the gross margin?\")\n",
        "retrieved_docs[0]"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "aMxNrMjFCEtr",
        "outputId": "1524c725-8b20-4d33-96c8-718ae5b832bb"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Document(page_content='Second Quarter of Fiscal Year 2024 Summary\\nThree Months Ended\\n July 30, 2023 April 30, 2023 July 31, 2022Quarter-over-Quarter\\nChangeYear-over-Year\\nChange\\n($ in millions, except per share data)\\nRevenue $ 13,507 $ 7,192 $ 6,704 88 % 101 %\\nGross margin 70.1 % 64.6 % 43.5 % 5.5 pts 26.6 pts\\nOperating expenses $ 2,662 $ 2,508 $ 2,416 6 % 10 %\\nOperating income $ 6,800 $ 2,140 $ 499 218 % 1,263 %\\nNet income $ 6,188 $ 2,043 $ 656 203 % 843 %\\nNet income per diluted share $ 2.48 $ 0.82 $ 0.26 202 % 854 %\\nWe specialize in markets where our computing platforms can provide tremendous acceleration for applications. These platforms incorporate\\nprocessors, interconnects, software, algorithms, systems, and services to deliver unique value. Our platforms address four large markets where\\nour expertise is critical: Data Center, Gaming, Professional Visualization, and Automotive.\\nRevenue for the second quarter of fiscal year 2024 was $13.51 billion, up 101% from a year ago and up 88% sequentially.\\nData Center revenue was up 171% from a year ago and up 141% sequentially, led by CSPs and large consumer internet companies. Strong\\ndemand for the NVIDIA HGX platform based on our Hopper and Ampere GPU architectures was primarily driven by the development of large\\nlanguage models and generative AI. Data Center Compute grew 195% from a year ago and 157% sequentially, largely reflecting the strong ramp\\nof our Hopper-based HGX platform. Networking was up 94% from a year ago and up 85% sequentially, primarily on strong growth in InfiniBand\\ninfrastructure to support our HGX platform. In the second quarter of fiscal year 2024, CSPs represented slightly more than half of our estimated\\nData Center end demand, with large consumer internet companies being the next largest end demand, followed by enterprise and high\\nperformance computing.\\nGaming revenue was up 22% from a year ago and up 11% sequentially, primarily reflecting demand for our GeForce RTX 40 Series GPUs\\nbased on the NVIDIA Ada Lovelace architecture following normalization of channel inventory levels.\\nProfessional Visualization revenue was down 24% from a year ago and up 28% sequentially. The year-on-year decrease primarily reflects lower\\nsell-in to partners following normalization of channel inventory levels. The sequential increase was primarily due to stronger enterprise\\nworkstation demand and the ramp of NVIDIA RTX products based on the Ada Lovelace Architecture.\\nAutomotive revenue was up 15% from a year ago and down 15% sequentially. The year-on-year increase was primarily driven by sales of self-\\ndriving platforms. The sequential decrease primarily reflects lower overall auto demand, particularly in China.\\nGross margin increased from a year ago and sequentially, primarily reflecting growth in Data Center sales. The year-on-year increase also\\nreflects the impact on the year-ago gross margin from $1.34 billion in inventory provisions and related charges.\\nOperating expenses were up 10% from a year ago and up 6% sequentially, primarily driven by compensation and benefits, including stock-based\\ncompensation, reflecting growth in employees and compensation increases.\\nMarket Platform Highlights\\nData Center revenue for the second quarter of fiscal year 2024 was $10.32 billion, up 171% from a year ago. We announced that the NVIDIA\\nGH200 Grace Hopper Superchip is available in the third quarter of fiscal year 2024; announced the NVIDIA L40S GPU - a universal data center\\nprocessor for compute-intensive applications, including AI training and inference, is available now; unveiled the NVIDIA MGX server reference\\ndesign; announced NVIDIA Spectrum-X, an accelerated networking platform for AI; and partnered with a\\n27', metadata={'source': './nvidia_10q_2023.pdf', 'page': 26})"
            ]
          },
          "metadata": {},
          "execution_count": 30
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "qa = ConversationalRetrievalChain.from_llm(OpenAI(temperature=0), retriever, memory=ConversationBufferMemory(memory_key=\"chat_history\", return_messages=True))"
      ],
      "metadata": {
        "id": "5_Qbm0VtCM-u"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "result = qa({\"question\": \"What is the gross margin?\"})\n",
        "result"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "IkYtOIsFCPgJ",
        "outputId": "f8733a4d-7409-4031-e667-c13e874977b5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'What is the gross margin?',\n",
              " 'chat_history': [HumanMessage(content='What is the gross margin?'),\n",
              "  AIMessage(content=' The gross margin for the second quarter and first half of fiscal year 2024 was 70.1% and 68.2%, respectively.')],\n",
              " 'answer': ' The gross margin for the second quarter and first half of fiscal year 2024 was 70.1% and 68.2%, respectively.'}"
            ]
          },
          "metadata": {},
          "execution_count": 34
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "result = qa({\"question\": \"What is the main contribution to it?\"})\n",
        "result"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "o1TcXM52CRWG",
        "outputId": "dbce7430-6130-4163-f8f8-8d35c1488089"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'What is the main contribution to it?',\n",
              " 'chat_history': [HumanMessage(content='What is the gross margin?'),\n",
              "  AIMessage(content=' The gross margin for the second quarter and first half of fiscal year 2024 was 70.1% and 68.2%, respectively.'),\n",
              "  HumanMessage(content='What is the main contribution to it?'),\n",
              "  AIMessage(content=' Higher revenue from Compute GPUs of 208% and 112%, respectively, and lower inventory provisions.')],\n",
              " 'answer': ' Higher revenue from Compute GPUs of 208% and 112%, respectively, and lower inventory provisions.'}"
            ]
          },
          "metadata": {},
          "execution_count": 35
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Hypothetical Questions"
      ],
      "metadata": {
        "id": "_RBj7LeCC9PF"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "functions = [\n",
        "    {\n",
        "      \"name\": \"hypothetical_questions\",\n",
        "      \"description\": \"Generate hypothetical questions\",\n",
        "      \"parameters\": {\n",
        "        \"type\": \"object\",\n",
        "        \"properties\": {\n",
        "          \"questions\": {\n",
        "            \"type\": \"array\",\n",
        "            \"items\": {\n",
        "                \"type\": \"string\"\n",
        "              },\n",
        "          },\n",
        "        },\n",
        "        \"required\": [\"questions\"]\n",
        "      }\n",
        "    }\n",
        "  ]"
      ],
      "metadata": {
        "id": "aVUhE281DEA0"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParser\n",
        "chain = (\n",
        "    {\"doc\": lambda x: x.page_content}\n",
        "    # Only asking for 3 hypothetical questions, but this could be adjusted\n",
        "    | ChatPromptTemplate.from_template(\"Generate a list of 3 hypothetical questions that the below document could be used to answer:\\n\\n{doc}\")\n",
        "    | ChatOpenAI(max_retries=0, model=\"gpt-4\").bind(functions=functions, function_call={\"name\": \"hypothetical_questions\"})\n",
        "    | JsonKeyOutputFunctionsParser(key_name=\"questions\")\n",
        ")"
      ],
      "metadata": {
        "id": "_fDL7U4ADNv_"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "hypothetical_questions = chain.batch(docs, {\"max_concurrency\": 5})"
      ],
      "metadata": {
        "id": "V6GaDghGDRAc"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "vectorstore = Chroma(\n",
        "    collection_name=\"hypo-questions\",\n",
        "    embedding_function=OpenAIEmbeddings()\n",
        ")\n",
        "store = InMemoryStore()\n",
        "id_key = \"doc_id\"\n",
        "retriever = MultiVectorRetriever(\n",
        "    vectorstore=vectorstore,\n",
        "    docstore=store,\n",
        "    id_key=id_key,\n",
        ")\n",
        "doc_ids = [str(uuid.uuid4()) for _ in docs]"
      ],
      "metadata": {
        "id": "0ZYWnM-PDTF4"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "question_docs = []\n",
        "for i, question_list in enumerate(hypothetical_questions):\n",
        "    question_docs.extend([Document(page_content=s,metadata={id_key: doc_ids[i]}) for s in question_list])"
      ],
      "metadata": {
        "id": "dcQgRxsKDVpD"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "question_docs"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "gAJ5AwV5Dz5M",
        "outputId": "0a9e5bae-8111-4292-eb29-32436540dd2f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[Document(page_content='What is the type of report filed by NVIDIA Corporation to the Securities and Exchange Commission?', metadata={'doc_id': '3fd2d11e-ff02-4281-993a-7bb966011e52'}),\n",
              " Document(page_content='What is the state of incorporation for NVIDIA Corporation?', metadata={'doc_id': '3fd2d11e-ff02-4281-993a-7bb966011e52'}),\n",
              " Document(page_content='What is the number of outstanding shares of common stock of NVIDIA Corporation as of August 18, 2023?', metadata={'doc_id': '3fd2d11e-ff02-4281-993a-7bb966011e52'}),\n",
              " Document(page_content=\"What were NVIDIA's financial results for the quarter ended July 30, 2023?\", metadata={'doc_id': '63b7d66e-3fe0-49b7-861b-cb86fd114dae'}),\n",
              " Document(page_content='What are the risk factors identified by NVIDIA for the quarter ended July 30, 2023?', metadata={'doc_id': '63b7d66e-3fe0-49b7-861b-cb86fd114dae'}),\n",
              " Document(page_content='How does NVIDIA Corporation disclose material financial information to its investors?', metadata={'doc_id': '63b7d66e-3fe0-49b7-861b-cb86fd114dae'}),\n",
              " Document(page_content='What was the net income of NVIDIA CORPORATION AND SUBSIDIARIES for the three months ended July 30, 2023?', metadata={'doc_id': '2072e3a7-3fd6-49b6-a729-5060facf828b'}),\n",
              " Document(page_content='How did the total operating expenses for the six months ended July 31, 2022, compare to the same period in 2023?', metadata={'doc_id': '2072e3a7-3fd6-49b6-a729-5060facf828b'}),\n",
              " Document(page_content='How did the gross profit for NVIDIA CORPORATION AND SUBSIDIARIES change from July 2022 to July 2023?', metadata={'doc_id': '2072e3a7-3fd6-49b6-a729-5060facf828b'}),\n",
              " Document(page_content=\"What was NVIDIA's net income for the three months ended July 30, 2023?\", metadata={'doc_id': '450ef64a-75ca-4ad5-ac9a-c89eb6a59b38'}),\n",
              " Document(page_content='What was the net change in unrealized gain for available-for-sale securities for the six months ended July 31, 2022?', metadata={'doc_id': '450ef64a-75ca-4ad5-ac9a-c89eb6a59b38'}),\n",
              " Document(page_content='How did the total comprehensive income for the first half of 2023 compare to the same period in 2022?', metadata={'doc_id': '450ef64a-75ca-4ad5-ac9a-c89eb6a59b38'}),\n",
              " Document(page_content='What is the difference in total assets of Nvidia Corporation and its subsidiaries between July 30, 2023, and January 29, 2023?', metadata={'doc_id': 'f412d4ef-7a64-4c7b-b238-f785606e0b97'}),\n",
              " Document(page_content='How has the amount of long-term debt held by Nvidia Corporation and its subsidiaries changed from January 29, 2023, to July 30, 2023?', metadata={'doc_id': 'f412d4ef-7a64-4c7b-b238-f785606e0b97'}),\n",
              " Document(page_content='What is the comparison between the total current assets and total current liabilities of Nvidia Corporation and its subsidiaries on July 30, 2023?', metadata={'doc_id': 'f412d4ef-7a64-4c7b-b238-f785606e0b97'}),\n",
              " Document(page_content=\"What was the total shareholders' equity of NVIDIA CORPORATION AND SUBSIDIARIES at the end of July 2023?\", metadata={'doc_id': '5ed8aa1e-47ab-41ee-9896-8b79ca4bfece'}),\n",
              " Document(page_content='How much was the net income of NVIDIA CORPORATION AND SUBSIDIARIES for the three months ended July 31, 2022?', metadata={'doc_id': '5ed8aa1e-47ab-41ee-9896-8b79ca4bfece'}),\n",
              " Document(page_content='How many shares did NVIDIA CORPORATION AND SUBSIDIARIES repurchase between May 1, 2022 and July 31, 2022?', metadata={'doc_id': '5ed8aa1e-47ab-41ee-9896-8b79ca4bfece'}),\n",
              " Document(page_content='What was the change in the number of outstanding shares of NVIDIA CORPORATION AND SUBSIDIARIES from January 29, 2023 to July 30, 2023?', metadata={'doc_id': 'e30eb8a3-3710-4dc2-8ace-90491f5b9d2b'}),\n",
              " Document(page_content='How much net income did NVIDIA CORPORATION AND SUBSIDIARIES report for the six months ended July 30, 2023?', metadata={'doc_id': 'e30eb8a3-3710-4dc2-8ace-90491f5b9d2b'}),\n",
              " Document(page_content=\"What was the total shareholders' equity of NVIDIA CORPORATION AND SUBSIDIARIES on July 31, 2022?\", metadata={'doc_id': 'e30eb8a3-3710-4dc2-8ace-90491f5b9d2b'}),\n",
              " Document(page_content=\"What was NVIDIA's net income for the six months ended July 31, 2022 and July 30, 2023?\", metadata={'doc_id': '389d807e-f8a8-4dad-a0c3-bb9c7e9fb9ee'}),\n",
              " Document(page_content='How much did NVIDIA spend on purchases of marketable securities in 2023 compared to 2022?', metadata={'doc_id': '389d807e-f8a8-4dad-a0c3-bb9c7e9fb9ee'}),\n",
              " Document(page_content='What was the change in cash, cash equivalents, and restricted cash from 2022 to 2023?', metadata={'doc_id': '389d807e-f8a8-4dad-a0c3-bb9c7e9fb9ee'}),\n",
              " Document(page_content='What are the significant accounting policies of NVIDIA Corporation and its subsidiaries?', metadata={'doc_id': 'f403d0bf-4d2e-4eb8-90bb-29ecef3c219f'}),\n",
              " Document(page_content='What change did NVIDIA make to the estimated useful life of its property, plant, and equipment in February 2023?', metadata={'doc_id': 'f403d0bf-4d2e-4eb8-90bb-29ecef3c219f'}),\n",
              " Document(page_content=\"How did the change in estimate of the useful lives of their equipment affect NVIDIA's net income for the first half of fiscal year 2024?\", metadata={'doc_id': 'f403d0bf-4d2e-4eb8-90bb-29ecef3c219f'}),\n",
              " Document(page_content='What were the financial implications for NVIDIA after the termination of the Arm Share Purchase Agreement with SoftBank?', metadata={'doc_id': '5cebfb4c-52ed-47ef-bb87-d5878af739d9'}),\n",
              " Document(page_content=\"What is the total amount of NVIDIA's future minimum lease payments for their operating leases as of July 30, 2023?\", metadata={'doc_id': '5cebfb4c-52ed-47ef-bb87-d5878af739d9'}),\n",
              " Document(page_content='How much did operating lease expenses change between the second quarter of fiscal years 2023 and 2024?', metadata={'doc_id': '5cebfb4c-52ed-47ef-bb87-d5878af739d9'}),\n",
              " Document(page_content='What was the operating cash flows used for operating leases for the six months ended July 30, 2023 and July 31, 2022?', metadata={'doc_id': 'a0cb8ec5-6f4e-4ed4-82f0-728fb1492c62'}),\n",
              " Document(page_content=\"What is the weighted average remaining lease term and the weighted average discount rate of NVIDIA's operating leases as of July 30, 2023?\", metadata={'doc_id': 'a0cb8ec5-6f4e-4ed4-82f0-728fb1492c62'}),\n",
              " Document(page_content='How much was the total stock-based compensation expense for the three months ended July 30, 2023 and July 31, 2022?', metadata={'doc_id': 'a0cb8ec5-6f4e-4ed4-82f0-728fb1492c62'}),\n",
              " Document(page_content=\"What was NVIDIA's net income in the second quarter of fiscal year 2023?\", metadata={'doc_id': '71fe091c-eeea-4d89-bd6c-6119872009fa'}),\n",
              " Document(page_content=\"What are the reasons for the increase in NVIDIA's effective tax rate?\", metadata={'doc_id': '71fe091c-eeea-4d89-bd6c-6119872009fa'}),\n",
              " Document(page_content=\"What could potentially change NVIDIA's provisions on federal, state and foreign tax related matters in the future?\", metadata={'doc_id': '71fe091c-eeea-4d89-bd6c-6119872009fa'}),\n",
              " Document(page_content=\"What is the total estimated fair value of NVIDIA's cash equivalents and marketable securities as of July 30, 2023?\", metadata={'doc_id': '2fb3f777-c3c0-4d7b-983a-d9e402aeaa71'}),\n",
              " Document(page_content=\"How much did NVIDIA's holdings in U.S. Treasury debt securities change from January 29, 2023 to July 30, 2023?\", metadata={'doc_id': '2fb3f777-c3c0-4d7b-983a-d9e402aeaa71'}),\n",
              " Document(page_content='What is the unrealized loss on corporate debt securities for NVIDIA as of January 29, 2023?', metadata={'doc_id': '2fb3f777-c3c0-4d7b-983a-d9e402aeaa71'}),\n",
              " Document(page_content=\"What is the total estimated fair value of NVIDIA's debt securities issued by the U.S. Treasury as of July 30, 2023?\", metadata={'doc_id': 'e6cc8c31-59c8-4b91-95ae-f765adbfc945'}),\n",
              " Document(page_content='How have the gross unrealized losses changed from January 29, 2023 to July 30, 2023?', metadata={'doc_id': 'e6cc8c31-59c8-4b91-95ae-f765adbfc945'}),\n",
              " Document(page_content=\"What is the amortized cost and estimated fair value of NVIDIA's marketable securities with a contractual maturity of 1-5 years as of July 30, 2023?\", metadata={'doc_id': 'e6cc8c31-59c8-4b91-95ae-f765adbfc945'}),\n",
              " Document(page_content=\"What is the fair value of NVIDIA's Cash equivalents and marketable securities as of July 30, 2023?\", metadata={'doc_id': '76a35a11-950a-4c50-83ca-64526282d761'}),\n",
              " Document(page_content=\"How does the value of NVIDIA's Corporate debt securities change between January 29, 2023 and July 30, 2023?\", metadata={'doc_id': '76a35a11-950a-4c50-83ca-64526282d761'}),\n",
              " Document(page_content='What is the original issuance value of the 3.70% Notes Due 2060 as of January 29, 2023 and July 30, 2023?', metadata={'doc_id': '76a35a11-950a-4c50-83ca-64526282d761'}),\n",
              " Document(page_content='What is the net carrying amount of the acquisition-related intangible assets as of January 29, 2023?', metadata={'doc_id': '87716d38-43f5-463c-a57c-e929cd856705'}),\n",
              " Document(page_content='How much has the amortization expense associated with intangible assets increased from the second quarter of fiscal year 2023 to the second quarter of fiscal year 2024?', metadata={'doc_id': '87716d38-43f5-463c-a57c-e929cd856705'}),\n",
              " Document(page_content='What was the total value of the inventories as of July 30, 2023?', metadata={'doc_id': '87716d38-43f5-463c-a57c-e929cd856705'}),\n",
              " Document(page_content='What was the total amount of other assets held by NVIDIA CORPORATION AND SUBSIDIARIES as of January 29, 2023?', metadata={'doc_id': '18dc0859-0e2f-4061-8048-cb326d84e8a9'}),\n",
              " Document(page_content='What is the difference between the taxes payable by NVIDIA CORPORATION AND SUBSIDIARIES in July 30, 2023 and January 29, 2023?', metadata={'doc_id': '18dc0859-0e2f-4061-8048-cb326d84e8a9'}),\n",
              " Document(page_content='How much did NVIDIA CORPORATION AND SUBSIDIARIES record as an expense for inventory purchase obligations in excess of current demand projections during the second quarter of fiscal years 2024 and 2023?', metadata={'doc_id': '18dc0859-0e2f-4061-8048-cb326d84e8a9'}),\n",
              " Document(page_content=\"What was the change in NVIDIA's deferred revenue between the first half of fiscal years 2024 and 2023?\", metadata={'doc_id': 'f6b575bd-1092-4168-b634-a16a1ffe0fd2'}),\n",
              " Document(page_content='How does NVIDIA mitigate the impact of foreign currency exchange rate movements on their operating expenses?', metadata={'doc_id': 'f6b575bd-1092-4168-b634-a16a1ffe0fd2'}),\n",
              " Document(page_content=\"What is the notional value of NVIDIA's foreign currency forward contracts designated as cash flow hedges as of July 30, 2023?\", metadata={'doc_id': 'f6b575bd-1092-4168-b634-a16a1ffe0fd2'}),\n",
              " Document(page_content='What is the carrying value of the 2.00% Notes Due 2031 as of July 30, 2023?', metadata={'doc_id': '901550dc-8d91-4a08-9bb2-af26785d27dc'}),\n",
              " Document(page_content='What is the interest rate for the 3.70% Notes Due 2060?', metadata={'doc_id': '901550dc-8d91-4a08-9bb2-af26785d27dc'}),\n",
              " Document(page_content=\"What is the total value of NVIDIA's outstanding inventory purchase and long-term supply and capacity obligations as of July 30, 2023?\", metadata={'doc_id': '901550dc-8d91-4a08-9bb2-af26785d27dc'}),\n",
              " Document(page_content='What is the total future purchase commitments of Nvidia Corporation for the fiscal year 2024?', metadata={'doc_id': '2892442c-79ba-49b8-be8b-217519f804a0'}),\n",
              " Document(page_content='What was the estimated amount of product warranty liabilities for Nvidia Corporation as of July 30, 2023?', metadata={'doc_id': '2892442c-79ba-49b8-be8b-217519f804a0'}),\n",
              " Document(page_content='What was the outcome of the securities class action lawsuit filed against Nvidia Corporation and certain Nvidia executives?', metadata={'doc_id': '2892442c-79ba-49b8-be8b-217519f804a0'}),\n",
              " Document(page_content='What are the legal proceedings that NVIDIA Corporation is currently involved in?', metadata={'doc_id': 'be12ca8b-a8af-4d14-99c2-117008a8a933'}),\n",
              " Document(page_content='How many shares of common stock did NVIDIA repurchase in the second quarter and first half of fiscal years 2023 and 2024?', metadata={'doc_id': 'be12ca8b-a8af-4d14-99c2-117008a8a933'}),\n",
              " Document(page_content='What is the total amount that NVIDIA has spent on their share repurchase program as of July 30, 2023?', metadata={'doc_id': 'be12ca8b-a8af-4d14-99c2-117008a8a933'}),\n",
              " Document(page_content='What segments does NVIDIA Corporation operate in and what do they include?', metadata={'doc_id': '04f65d0a-630d-4755-928f-423373d97a84'}),\n",
              " Document(page_content='How does the Chief Executive Officer of NVIDIA Corporation review financial performance?', metadata={'doc_id': '04f65d0a-630d-4755-928f-423373d97a84'}),\n",
              " Document(page_content=\"What types of expenses are included in the 'All Other' category in NVIDIA Corporation's financial statements?\", metadata={'doc_id': '04f65d0a-630d-4755-928f-423373d97a84'}),\n",
              " Document(page_content='How much has the revenue of NVIDIA Corporation and its subsidiaries increased from July 2022 to July 2023?', metadata={'doc_id': 'aa647635-2076-435d-b92d-f3602585e8fc'}),\n",
              " Document(page_content=\"What were the major contributing factors to the operating income or loss in the 'All Other' category for the three months ended July 2023 and July 2022?\", metadata={'doc_id': 'aa647635-2076-435d-b92d-f3602585e8fc'}),\n",
              " Document(page_content='How has the operating income of the Compute & Networking division changed from the six months ended July 2022 to the six months ended July 2023?', metadata={'doc_id': 'aa647635-2076-435d-b92d-f3602585e8fc'}),\n",
              " Document(page_content=\"What percentage of NVIDIA's total revenue in the second quarter of fiscal year 2024 came from a large cloud service provider?\", metadata={'doc_id': '16329c7f-d707-449a-b94d-c71713d76d75'}),\n",
              " Document(page_content='How much did NVIDIA earn from the data center market in the first half of fiscal year 2023?', metadata={'doc_id': '16329c7f-d707-449a-b94d-c71713d76d75'}),\n",
              " Document(page_content=\"How has NVIDIA's revenue from China (including Hong Kong) changed between July 2022 and July 2023?\", metadata={'doc_id': '16329c7f-d707-449a-b94d-c71713d76d75'}),\n",
              " Document(page_content=\"What are the potential risks and uncertainties that could influence NVIDIA's financial performance?\", metadata={'doc_id': '3cdf9ce9-cb64-43ce-981d-463005a5060b'}),\n",
              " Document(page_content='How has NVIDIA anticipated and responded to the increased demand for its data center systems and products?', metadata={'doc_id': '3cdf9ce9-cb64-43ce-981d-463005a5060b'}),\n",
              " Document(page_content=\"What are NVIDIA's plans and strategies for transitioning the architecture of its Data Center, Professional Visualization, and Gaming products?\", metadata={'doc_id': '3cdf9ce9-cb64-43ce-981d-463005a5060b'}),\n",
              " Document(page_content='What are the potential impacts of reducing channel inventory of prior architectures before introducing new products?', metadata={'doc_id': 'd07c460d-9e90-4124-8d1a-f0ca06a76ea1'}),\n",
              " Document(page_content=\"How does the complexity of bringing up new product architectures impact the company's revenue and costs?\", metadata={'doc_id': 'd07c460d-9e90-4124-8d1a-f0ca06a76ea1'}),\n",
              " Document(page_content=\"What are the potential financial impacts of additional export restrictions on the company's A100 and H100 integrated circuits?\", metadata={'doc_id': 'd07c460d-9e90-4124-8d1a-f0ca06a76ea1'}),\n",
              " Document(page_content='What was the revenue for the second quarter of fiscal year 2024 and how does it compare to the same period in the previous year?', metadata={'doc_id': 'd67061da-9c02-491d-a999-c8347be7e5e4'}),\n",
              " Document(page_content='How did the revenue from each market platform (Data Center, Gaming, Professional Visualization, Automotive) change in the second quarter of fiscal year 2024 compared to the previous year?', metadata={'doc_id': 'd67061da-9c02-491d-a999-c8347be7e5e4'}),\n",
              " Document(page_content='What were the main factors that contributed to the changes in revenue, gross margin, and operating expenses in the second quarter of fiscal year 2024?', metadata={'doc_id': 'd67061da-9c02-491d-a999-c8347be7e5e4'}),\n",
              " Document(page_content='What was the gaming revenue for the second quarter of fiscal year 2024?', metadata={'doc_id': '9876919c-0e26-4910-87e5-b287127fa19c'}),\n",
              " Document(page_content='What was the percentage increase in gaming revenue from a year ago?', metadata={'doc_id': '9876919c-0e26-4910-87e5-b287127fa19c'}),\n",
              " Document(page_content='What new product or service was announced for the gaming sector in the second quarter of fiscal year 2024?', metadata={'doc_id': '9876919c-0e26-4910-87e5-b287127fa19c'}),\n",
              " Document(page_content='What led to the increase in revenue in the Compute & Networking segment in the second quarter and first half of fiscal year 2024?', metadata={'doc_id': '9def79d8-d156-4632-9541-2c7da7d3df56'}),\n",
              " Document(page_content='Why was there a decrease in Graphics segment revenue in the first half of fiscal year 2024 compared to the same period in fiscal year 2023?', metadata={'doc_id': '9def79d8-d156-4632-9541-2c7da7d3df56'}),\n",
              " Document(page_content='What factors contributed to the increase in overall gross margin in the second quarter and first half of fiscal year 2024?', metadata={'doc_id': '9def79d8-d156-4632-9541-2c7da7d3df56'}),\n",
              " Document(page_content='What were the provisions for inventory and excess inventory purchase obligations for the second quarter and first half of fiscal year 2024 compared to the same periods in 2023?', metadata={'doc_id': 'e39ef264-49f6-4817-af42-59572fdc9832'}),\n",
              " Document(page_content='How did sales of inventory that was previously written off or down, or settlements of excess inventory purchase obligations, affect the gross margin in fiscal years 2023 and 2024?', metadata={'doc_id': 'e39ef264-49f6-4817-af42-59572fdc9832'}),\n",
              " Document(page_content='What were the operating expenses and operating income for the second quarter and first half of fiscal year 2024, and how did these figures change from the previous year?', metadata={'doc_id': 'e39ef264-49f6-4817-af42-59572fdc9832'}),\n",
              " Document(page_content=\"What were the main reasons for the increase in the Compute & Networking segment's operating income in the second quarter and first half of fiscal year 2024?\", metadata={'doc_id': '8907a4b6-3a6a-4632-a0a2-392fc344149f'}),\n",
              " Document(page_content=\"How did inventory provisions impact the Graphics segment's operating income in the second quarter and first half of fiscal year 2024 compared to the same periods in fiscal year 2023?\", metadata={'doc_id': '8907a4b6-3a6a-4632-a0a2-392fc344149f'}),\n",
              " Document(page_content='What factors contributed to the increase in the effective tax rate in the second quarter and first half of fiscal year 2024 compared to the same periods in fiscal year 2023?', metadata={'doc_id': '8907a4b6-3a6a-4632-a0a2-392fc344149f'}),\n",
              " Document(page_content='How has the net cash provided by operating activities changed from the first half of fiscal year 2023 to the first half of fiscal year 2024?', metadata={'doc_id': 'e5cb1264-b013-4342-8836-84b791349704'}),\n",
              " Document(page_content='What are the primary sources of liquidity for the company as of July 30, 2023?', metadata={'doc_id': 'e5cb1264-b013-4342-8836-84b791349704'}),\n",
              " Document(page_content='How much does the company expect to pay in cash taxes in the third quarter of fiscal year 2024?', metadata={'doc_id': 'e5cb1264-b013-4342-8836-84b791349704'}),\n",
              " Document(page_content='How much money was returned in share repurchases and cash dividends in the second quarter of fiscal year 2024?', metadata={'doc_id': 'd19ac1aa-a35f-4f1f-97cd-c4927262f7e9'}),\n",
              " Document(page_content='What is the total amount available for share repurchase as of August 24, 2023?', metadata={'doc_id': 'd19ac1aa-a35f-4f1f-97cd-c4927262f7e9'}),\n",
              " Document(page_content=\"What is the company's aggregate debt maturities as of July 30, 2023?\", metadata={'doc_id': 'd19ac1aa-a35f-4f1f-97cd-c4927262f7e9'}),\n",
              " Document(page_content=\"What impact has climate change regulations had on the company's operations?\", metadata={'doc_id': 'cf0511ae-2bf2-4fe0-b16b-d839ea7817e6'}),\n",
              " Document(page_content=\"Have there been any significant changes in the company's financial market risks since January 29, 2023?\", metadata={'doc_id': 'cf0511ae-2bf2-4fe0-b16b-d839ea7817e6'}),\n",
              " Document(page_content=\"Have there been any changes in the company's internal control over financial reporting in the second quarter of fiscal year 2024?\", metadata={'doc_id': 'cf0511ae-2bf2-4fe0-b16b-d839ea7817e6'}),\n",
              " Document(page_content='What are the risks involved in purchasing or owning NVIDIA common stock?', metadata={'doc_id': 'bfdb8bf5-cf83-4195-836a-bdab4cde8df3'}),\n",
              " Document(page_content='How does NVIDIA plan to meet the evolving needs of the industry and markets to maintain their financial results?', metadata={'doc_id': 'bfdb8bf5-cf83-4195-836a-bdab4cde8df3'}),\n",
              " Document(page_content=\"What are NVIDIA's strategies for developing new products and technologies, and what could the potential impact be if these efforts are not successful?\", metadata={'doc_id': 'bfdb8bf5-cf83-4195-836a-bdab4cde8df3'}),\n",
              " Document(page_content='What challenges could NVIDIA face due to inaccurate estimates of customer demand?', metadata={'doc_id': '55b53939-80b4-4e14-a35b-33556c2ddb77'}),\n",
              " Document(page_content='How does NVIDIA manage mismatches between supply and demand?', metadata={'doc_id': '55b53939-80b4-4e14-a35b-33556c2ddb77'}),\n",
              " Document(page_content=\"How could changes in governmental policies or third-party business decisions impact NVIDIA's supply and demand?\", metadata={'doc_id': '55b53939-80b4-4e14-a35b-33556c2ddb77'}),\n",
              " Document(page_content='What could happen if the company underestimates the future demand for their products?', metadata={'doc_id': '17c73e73-6365-4323-9e70-097cf9d6de4f'}),\n",
              " Document(page_content=\"How might the company's financial results be impacted if they are unable to execute architectural transitions as planned?\", metadata={'doc_id': '17c73e73-6365-4323-9e70-097cf9d6de4f'}),\n",
              " Document(page_content='What risks could the company face due to the increase in their purchase obligations and prepaids?', metadata={'doc_id': '17c73e73-6365-4323-9e70-097cf9d6de4f'}),\n",
              " Document(page_content=\"How could the impact of generative AI models on the company's revenue or forecasted demand be estimated?\", metadata={'doc_id': 'bc22fda6-d380-4505-b854-bd6075e31934'}),\n",
              " Document(page_content=\"What could be the potential impact of geopolitical tensions involving Taiwan and China on the company's revenue and supply continuity?\", metadata={'doc_id': 'bc22fda6-d380-4505-b854-bd6075e31934'}),\n",
              " Document(page_content=\"How could changes in the cryptocurrency market and standards, such as the Ethereum 2.0 merge, impact the demand for the company's products?\", metadata={'doc_id': 'bc22fda6-d380-4505-b854-bd6075e31934'}),\n",
              " Document(page_content='What would be the impact if our foundries failed to develop or implement high quality process technologies?', metadata={'doc_id': '1cf0f6df-e762-4c72-b61d-393e885c62d6'}),\n",
              " Document(page_content='What could be the consequences of the loss of a supplier and the additional expense and/or production delays as a result of qualifying a new foundry or subcontractor?', metadata={'doc_id': '1cf0f6df-e762-4c72-b61d-393e885c62d6'}),\n",
              " Document(page_content='How could international sales and operations expose us to risks that could harm our business and what would be the potential impact of these risks?', metadata={'doc_id': '1cf0f6df-e762-4c72-b61d-393e885c62d6'}),\n",
              " Document(page_content=\"What would be the potential impact of natural disasters, power shortages, or other disruptions on the company's operations?\", metadata={'doc_id': 'd08c373d-90fd-498f-b2f9-8237b04ef499'}),\n",
              " Document(page_content=\"How might the company's reliance on third-party systems and services affect its business in the case of service interruptions or defects?\", metadata={'doc_id': 'd08c373d-90fd-498f-b2f9-8237b04ef499'}),\n",
              " Document(page_content=\"What are some risks and challenges associated with the company's business investments or acquisitions?\", metadata={'doc_id': 'd08c373d-90fd-498f-b2f9-8237b04ef499'}),\n",
              " Document(page_content=\"What are the potential challenges faced when integrating acquisition target systems into the company's own?\", metadata={'doc_id': '1f01b2c4-15fd-4682-b13b-3e64aa4fbb3a'}),\n",
              " Document(page_content='What is the impact on the company if it loses or is prevented from selling to any of its end customers?', metadata={'doc_id': '1f01b2c4-15fd-4682-b13b-3e64aa4fbb3a'}),\n",
              " Document(page_content='How might the complex laws, rules and regulations affect the operations of the business?', metadata={'doc_id': '1f01b2c4-15fd-4682-b13b-3e64aa4fbb3a'}),\n",
              " Document(page_content=\"What impact could changes in antitrust legislation and increased focus on cybersecurity vulnerabilities have on the company's compliance costs?\", metadata={'doc_id': '97706177-048e-41c3-9469-77ea6c0dedfb'}),\n",
              " Document(page_content='How might changes in public perception of governments in regions where the company operates affect its business operations?', metadata={'doc_id': '97706177-048e-41c3-9469-77ea6c0dedfb'}),\n",
              " Document(page_content=\"What potential effects could export control restrictions on AI technologies have on the company's product and service offerings?\", metadata={'doc_id': '97706177-048e-41c3-9469-77ea6c0dedfb'}),\n",
              " Document(page_content=\"What could be the potential impact of export controls on the company's ability to provide services such as NVIDIA AI cloud services?\", metadata={'doc_id': 'e510e4a6-12cd-4338-8a0b-c89d999346f2'}),\n",
              " Document(page_content=\"How might changes in export control rules affect the company's business and its customers?\", metadata={'doc_id': 'e510e4a6-12cd-4338-8a0b-c89d999346f2'}),\n",
              " Document(page_content=\"What is the possible effect of the USG's export restrictions and licensing requirements on the company's operations and revenue?\", metadata={'doc_id': 'e510e4a6-12cd-4338-8a0b-c89d999346f2'}),\n",
              " Document(page_content=\"How might changes in the US export control rules impact the company's business in China and other regions?\", metadata={'doc_id': '1ec68379-958f-4af9-adda-6beac3b77c6c'}),\n",
              " Document(page_content=\"What could be the potential impact of the Chinese government's restrictions on gaming activities on the company's revenue?\", metadata={'doc_id': '1ec68379-958f-4af9-adda-6beac3b77c6c'}),\n",
              " Document(page_content=\"How could the company's operations be affected by regulatory proceedings, claims, or investigations?\", metadata={'doc_id': '1ec68379-958f-4af9-adda-6beac3b77c6c'}),\n",
              " Document(page_content='How many shares of common stock did the company repurchase during the second quarter of fiscal year 2024?', metadata={'doc_id': 'b00fda71-3ebc-4a65-bc7f-28c70c359cef'}),\n",
              " Document(page_content='What was the total cost of the shares repurchased since the inception of the share repurchase program?', metadata={'doc_id': 'b00fda71-3ebc-4a65-bc7f-28c70c359cef'}),\n",
              " Document(page_content='What was the total value of shares that may yet be purchased under the program as of July 30, 2023?', metadata={'doc_id': 'b00fda71-3ebc-4a65-bc7f-28c70c359cef'}),\n",
              " Document(page_content='What certifications are required by Rule 13a-14(a) and Rule 13a-14(b) of the Securities Exchange Act of 1934?', metadata={'doc_id': 'a61c5fca-2cd3-48c2-88e5-44b464f76643'}),\n",
              " Document(page_content='What are the different components of the Inline XBRL document?', metadata={'doc_id': 'a61c5fca-2cd3-48c2-88e5-44b464f76643'}),\n",
              " Document(page_content='How can a shareholder get access to the exhibits that are not contained in the document?', metadata={'doc_id': 'a61c5fca-2cd3-48c2-88e5-44b464f76643'}),\n",
              " Document(page_content='Who signed the report on behalf of NVIDIA Corporation?', metadata={'doc_id': '61c635f5-9a1c-47e6-9dd6-747ab67b9e6e'}),\n",
              " Document(page_content='What is the position of Colette M. Kress in NVIDIA Corporation?', metadata={'doc_id': '61c635f5-9a1c-47e6-9dd6-747ab67b9e6e'}),\n",
              " Document(page_content='On what date was the report signed by the authorized officer of NVIDIA Corporation?', metadata={'doc_id': '61c635f5-9a1c-47e6-9dd6-747ab67b9e6e'}),\n",
              " Document(page_content='Who is responsible for establishing and maintaining disclosure controls and procedures for NVIDIA Corporation?', metadata={'doc_id': '9913aafc-71ad-4ac5-be7e-5002de4d5195'}),\n",
              " Document(page_content='According to the certification, has there been any change in the registrant’s internal control over financial reporting that could materially affect it?', metadata={'doc_id': '9913aafc-71ad-4ac5-be7e-5002de4d5195'}),\n",
              " Document(page_content='What assurances does the certification provide about the accuracy and fairness of the financial statements included in the report?', metadata={'doc_id': '9913aafc-71ad-4ac5-be7e-5002de4d5195'}),\n",
              " Document(page_content='Who is responsible for establishing and maintaining disclosure controls and procedures for NVIDIA Corporation?', metadata={'doc_id': '6c8cbd1d-58da-4be2-b23b-6523332d8d1a'}),\n",
              " Document(page_content=\"What are some of the responsibilities of the registrant's certifying officers in regard to the company's internal control over financial reporting?\", metadata={'doc_id': '6c8cbd1d-58da-4be2-b23b-6523332d8d1a'}),\n",
              " Document(page_content='What actions are taken if there are deficiencies or weaknesses in the design or operation of internal control over financial reporting?', metadata={'doc_id': '6c8cbd1d-58da-4be2-b23b-6523332d8d1a'}),\n",
              " Document(page_content='What is the relevance of Rule 13a-14(b) of the Securities Exchange Act of 1934 in the certification of Jen-Hsun Huang, the President and CEO of NVIDIA Corporation?', metadata={'doc_id': 'fc92ee0a-1fc1-4cd6-857c-e5d683152053'}),\n",
              " Document(page_content=\"What is the assurance given by Jen-Hsun Huang regarding the Company's Quarterly Report on Form 10-Q for the period ended July 30, 2023?\", metadata={'doc_id': 'fc92ee0a-1fc1-4cd6-857c-e5d683152053'}),\n",
              " Document(page_content='What is the significance of Section 906 of 18 U.S.C. § 1350 in the provided certification?', metadata={'doc_id': 'fc92ee0a-1fc1-4cd6-857c-e5d683152053'}),\n",
              " Document(page_content=\"What does the certification document certify about the Company's Quarterly Report?\", metadata={'doc_id': '8fde4b8c-4862-4f04-a091-43606b98b84c'}),\n",
              " Document(page_content='What is the role of Colette M. Kress at NVIDIA Corporation?', metadata={'doc_id': '8fde4b8c-4862-4f04-a091-43606b98b84c'}),\n",
              " Document(page_content='What is the purpose of this certification in relation to the Form 10-Q?', metadata={'doc_id': '8fde4b8c-4862-4f04-a091-43606b98b84c'})]"
            ]
          },
          "metadata": {},
          "execution_count": 41
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "retriever.vectorstore.add_documents(question_docs)\n",
        "retriever.docstore.mset(list(zip(doc_ids, docs)))"
      ],
      "metadata": {
        "id": "3AUNa_ipDX6F"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "qa = ConversationalRetrievalChain.from_llm(OpenAI(temperature=0), retriever, memory=ConversationBufferMemory(memory_key=\"chat_history\", return_messages=True))"
      ],
      "metadata": {
        "id": "hUsA2566DcKj"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "result = qa({\"question\": \"What is the gross margin?\"})\n",
        "result"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ewO57k2nDe5i",
        "outputId": "d0e29a45-31f7-4c6e-b490-0af01bdf073b"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'What is the gross margin?',\n",
              " 'chat_history': [HumanMessage(content='What is the gross margin?'),\n",
              "  AIMessage(content=' The gross margin was 70.1% for the second quarter and 68.2% for the first half of fiscal year 2024.')],\n",
              " 'answer': ' The gross margin was 70.1% for the second quarter and 68.2% for the first half of fiscal year 2024.'}"
            ]
          },
          "metadata": {},
          "execution_count": 44
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "result = qa({\"question\": \"What is the main contribution to it?\"})\n",
        "result"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Up_xzm8ADgTu",
        "outputId": "5e72a0fe-239f-4991-a08f-04655189cb54"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'What is the main contribution to it?',\n",
              " 'chat_history': [HumanMessage(content='What is the gross margin?'),\n",
              "  AIMessage(content=' The gross margin was 70.1% for the second quarter and 68.2% for the first half of fiscal year 2024.'),\n",
              "  HumanMessage(content='What is the main contribution to it?'),\n",
              "  AIMessage(content=' Higher revenue from Compute GPUs.')],\n",
              " 'answer': ' Higher revenue from Compute GPUs.'}"
            ]
          },
          "metadata": {},
          "execution_count": 45
        }
      ]
    }
  ]
}